package com.doit.demo03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class test {
    public static void main(String[] args) {

        List<Person>list = new ArrayList<>();
        list.add(new Person("金莲",10));
        list.add(new Person("大郎",10));
        list.add(new Person("西门庆",100));
        list.add(new Person("武松",108));
        list.add(new Person("打虎",107));

        Collections.sort(list);
        System.out.println(list);

        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o2.getAge()-o1.getAge();//降序
            }
        });
        System.out.println(list);

        Collections.sort(list, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        System.out.println(list);
    }
}
